$(function() {
	$('#btn_delete').click(function(){
		var rows = $('#datagrid').datagrid('getSelections');
		if (rows.length == 0) {
			$.messager.alert('警告', '请至少选择一条记录!', 'warning');
			return;
		}
		
		$.messager.confirm("操作提示","您确定要删除这些主题吗？",function(data) {
			if (data) {
				var ids = '';
				for ( var i = 0; i < rows.length; i++) {
					if (i > 0) {
						ids += ",";
					}
					ids += rows[i].id;
				}
			}
			$.ajax({
				url : '/AQAppServer/theme/deleteWebTheme',
				type : 'POST',
				dataType:'json',
				data:{'ids':ids},
				success : function(data) {
					data = toJson(data);
					if (data.flag == 0) {
						$("#datagrid").datagrid('reload');
					} else {
						$.messager.alert('错误',data.flag,'error');
					}
				},
				error : function() {
					$.messager.alert('错误','操作失败!','error');
				}
			});
		});
	});
	
	$('#btn_delete2').click(function(){
		var rows = $('#datagrid2').datagrid('getSelections');
		if (rows.length == 0) {
			$.messager.alert('警告', '请至少选择一条记录!', 'warning');
			return;
		}
		
		$.messager.confirm("操作提示","您确定要删除这些回复吗？",function(data) {
			if (data) {
				var ids = '';
				for ( var i = 0; i < rows.length; i++) {
					if (i > 0) {
						ids += ",";
					}
					ids += rows[i].id;
				}
			}
			$.ajax({
				url : '/AQAppServer/theme/deleteWebComment',
				type : 'POST',
				dataType:'json',
				data:{'ids':ids},
				success : function(data) {
					data = toJson(data);
					if (data.flag == 0) {
						$("#datagrid2").datagrid('reload');
					} else {
						$.messager.alert('错误',data.flag,'error');
					}
				},
				error : function() {
					$.messager.alert('错误','操作失败!','error');
				}
			});
		});
	});
	
	$('#btn_stop').click(function(){
		var rows = $('#datagrid').datagrid('getSelections');
		if (rows.length != 1) {
			$.messager.alert('警告', '必须选择一条记录!', 'warning');
			return;
		}
		$.ajax({
			url : '/AQAppServer/theme/cancerTopWebTheme',
			type : 'POST',
			dataType:'json',
			data:{'id':rows[0].id},
			success : function(data) {
				data = toJson(data);
				if (data.flag == 0) {
					$("#datagrid").datagrid('reload');
				} else {
					$.messager.alert('错误',data.desc,'error');
				}
			},
			error : function() {
				$.messager.alert('错误','操作失败!','error');
			}
		});
	});
	
	var $win = $('#edit-window').window({
		title : '回复列表',
		width : 680,
		height : 480,
		top : ($(window).height() - 480) * 0.5,
		left : ($(window).width() - 680) * 0.5,
		shadow : true,
		modal : true,
		closed : true,
		minimizable : false,
		maximizable : false,
		collapsible : false
	});
	
	$('#btn_comment').click(function(){
		var rows = $('#datagrid').datagrid('getSelections');
		if (rows.length != 1) {
			$.messager.alert('警告', '必须选择一条记录!', 'warning');
			return;
		}
		$win.window('open');
		$('#datagrid2').datagrid({
			url:'/AQAppServer/theme/queryWebComment',
			queryParams:{themeId:rows[0].id}
		});
		$('#datagrid2').datagrid('reload');
	});
	
	$('#btn_totop').click(function(){
		var rows = $('#datagrid').datagrid('getSelections');
		if (rows.length != 1) {
			$.messager.alert('警告', '必须选择一条记录!', 'warning');
			return;
		}
		$.ajax({
			url : '/AQAppServer/theme/toTopWebTheme',
			type : 'POST',
			dataType:'json',
			data:{'id':rows[0].id},
			success : function(data) {
				data = toJson(data);
				if (data.flag == 0) {
					$("#datagrid").datagrid('reload');
				} else {
					$.messager.alert('错误',data.desc,'warning');
				}
			},
			error : function() {
				$.messager.alert('错误','操作失败!','error');
			}
		});
	});
});